package main

import "fmt"

func main() {
	c := make(chan int)

	go func() {
		for i := 0; i < 5; i++ {
			c <- i
		}
		//通过close关键字关闭channel
		close(c)
	}()
	/*	for {
		if data, ok := <-c; ok {
			//ok为true说明channel没有关闭，为false说明管道已经关闭
			fmt.Println(data)
		} else {
			break
		}
	}*/
	for data := range c {
		fmt.Println(data)
	}
}
